package data.set.adaptator;

import java.util.ArrayList;
import java.util.Iterator;

import tools.Pair;

import data.set.OfflineSet;
import data.set.OfflineSetIterator;

public class OfflineSet_FromMultipleOfflineSet<X> implements OfflineSet<X>{

	private ArrayList<OfflineSet<X>> allSets;
	private long size;

	public OfflineSet_FromMultipleOfflineSet(){
		allSets = new ArrayList<OfflineSet<X>>();
		size =0L;
	}

	private void updateSize(){
		size = 0;
		for (OfflineSet<X> d: allSets)
			size+=d.size();
	}

	private int getSetFromIndex(int i){
		int index = -1;
		int cumSize = 0;
		for (OfflineSet<X> d: allSets){
			cumSize +=  d.size();
			index++;
			if(i<cumSize)
				return index;
		}
		return -1;
	}

	public void add(OfflineSet<X> data){
		allSets.add(data);
		updateSize();
	}

	public Iterator<X> iterator() {
		return null;
	}

	public OfflineSetIterator<X> inputsetiterator() {
		// TODO Auto-generated method stub
		return null;
	}

	public X getObject(int id) {
		// non implementable dans le cas présent
		return null;
	}

	public long size() {
		return size;
	}



	public class IT implements OfflineSetIterator<X>{

		private OfflineSetIterator<X> currentIter;
		private int currentSet;

		public IT(){
			currentSet = 0;
			currentIter = allSets.get(currentSet).inputsetiterator();
		}

		public boolean hasNext() {
			if(currentIter.hasNext())
				return true;

			if(currentSet<allSets.size())
				return true;
			
			return false;
		}

		public X getCurrentObject() {
			
			return currentIter.getCurrentObject();
		}

		public int getCurrentId() {
			
			return currentIter.getCurrentId();
		}

		public void next() {
			if(currentIter.hasNext()){
				currentIter.next();
				return;
			}
			
			currentSet++;
			currentIter = allSets.get(currentSet).inputsetiterator();
			
			currentIter.next();
		}

	}
}
